package com.yanqu.road.server.manger;

import com.yanqu.road.entity.config.goods.MammonConfig;
import com.yanqu.road.entity.enums.eMammonRangeType;
import com.yanqu.road.logic.bussiness.config.DecorationBussiness;
import com.yanqu.road.server.TempMgr;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class MammonConfigMgr extends TempMgr {
    private static Map<Integer, MammonConfig> mammonConfigMap;
    private static List<Integer> mammonDecorationIdList;
    private static List<Integer> localMammonDecorationIdList;
    private static List<Integer> crossMammonDecorationIdList;
    private static List<Integer> crossAreaMammonDecorationIdList;

    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean stop() {
        return false;
    }

    @Override
    public boolean reloadConfig() {
        mammonConfigMap = DecorationBussiness.getMammonConfigMap();
        if(mammonConfigMap.size() <= 0){
            return false;
        }
        initMammonDecorationIdList();
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    private static void initMammonDecorationIdList(){
        mammonDecorationIdList = new ArrayList<>(mammonConfigMap.keySet());
        List<Integer> tempLocalList = new ArrayList<>();
        List<Integer> tempCrossList = new ArrayList<>();
        List<Integer> tempCrossAreaList = new ArrayList<>();
        for(MammonConfig mammonConfig : mammonConfigMap.values()){
            if(mammonConfig.getType() == eMammonRangeType.LocalMammon.getValue()){
                tempLocalList.add(mammonConfig.getMammonDecorationId());
            } else if (mammonConfig.getType() == eMammonRangeType.CrossMammon.getValue()) {
                tempCrossList.add(mammonConfig.getMammonDecorationId());
            } else if (mammonConfig.getType() == eMammonRangeType.CrossAreaMammon.getValue()) {
                tempCrossAreaList.add(mammonConfig.getMammonDecorationId());
            }
        }
        localMammonDecorationIdList = tempLocalList;
        crossMammonDecorationIdList = tempCrossList;
        crossAreaMammonDecorationIdList = tempCrossAreaList;
    }

    public static MammonConfig getMammonConfig(int decorationId){
        return mammonConfigMap.get(decorationId);
    }

    public static List<Integer> getMammonDecorationIdList(){
        return new ArrayList<>(mammonDecorationIdList);
    }

    public static List<Integer> getLocalMammonDecorationIdList(){
        return new ArrayList<>(localMammonDecorationIdList);
    }

    public static List<Integer> getCrossMammonDecorationIdList(){
        return new ArrayList<>(crossMammonDecorationIdList);
    }

    public static boolean isMammonDecorationId(int decorationId){
        return mammonDecorationIdList.contains(decorationId);
    }

    public static boolean isLocalMammonDecorationId(int decorationId){
        return localMammonDecorationIdList.contains(decorationId);
    }

    public static boolean isCrossMammonDecorationId(int decorationId){
        return crossMammonDecorationIdList.contains(decorationId);
    }

    public static boolean isCrossAreaMammonDecorationId(int decorationId) {
        // 这个也是跨服称号，存储的位置跟分组不同
        return crossAreaMammonDecorationIdList.contains(decorationId);
    }
}
